package cn.tedu.hospital.management.controller;


import cn.tedu.common.web.JsonResult;
import cn.tedu.hospital.management.pojo.param.HosAddNewParam;
import cn.tedu.hospital.management.pojo.param.HospitalAddNewParam;
import cn.tedu.hospital.management.pojo.param.HospitalParam;
import cn.tedu.hospital.management.pojo.param.HospitalUpdateInfoParam;
import cn.tedu.hospital.management.service.IHospitalService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "医院管理")
@RestController
@RequestMapping("/hospital")
public class HospitalController {

    @Autowired
    private IHospitalService hospitalService;

    @PostMapping("{name}/avatar")
    public JsonResult avatar(@PathVariable String name, HosAddNewParam hosAddNewParam){

        System.out.println("currentPrincipal = " + name + ", staffAvatarParam = !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + hosAddNewParam);
        hospitalService.avatar(name,hosAddNewParam);
        return JsonResult.ok();
    }


    @PostMapping("/add-new")
    @ApiOperation("添加医院")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew( HospitalAddNewParam hospitalAddNewParam) {
        hospitalService.insert(hospitalAddNewParam);
        return JsonResult.ok();

    }

    @GetMapping("")
    @ApiOperation("查询医院")
    @ApiOperationSupport(order = 250)
    public JsonResult listAll() {
        return JsonResult.ok(hospitalService.listAll());

    }


    @PostMapping("/{id}/delete")
    @ApiOperation("删除医院")
    @ApiOperationSupport(order = 400)
    public JsonResult delectById(@PathVariable Long id) {
        hospitalService.delectById(id);
        return JsonResult.ok();
    }


/*    @ApiOperation("新增医院")
    @ApiOperationSupport(order = 100)
    @PostMapping("add/new")
    public JsonResult addNew(HospitalAddNewParam hospitalAddNewParam){
        hospitalService.addNew(hospitalAddNewParam);
        return JsonResult.ok();
    }*/


 /*   @ApiOperation("根据id删除医院")
    @ApiOperationSupport(order = 200)
    @PostMapping({"/{id}/delete"})
    public JsonResult delete(@PathVariable Long id){
        hospitalService.delete(id);
        return JsonResult.ok();
    }*/


    @ApiOperation("根据id修改医院信息")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult updateInfoById(@PathVariable Long id, @Valid HospitalUpdateInfoParam hospitalUpdateInfoParam){
        hospitalService.updateInfoById(id,hospitalUpdateInfoParam);
        return JsonResult.ok();
    }


/*    @ApiOperation("根据id查询医院信息")
    @ApiOperationSupport(order = 400)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable Long id){
        HospitalStandardVO standardVO = hospitalService.getStandardById(id);
        return JsonResult.ok(standardVO);
    }*/

    @GetMapping("/big-citys")
    public JsonResult getBigCity(){
        return JsonResult.ok(hospitalService.getProvince());
    }

    @GetMapping("/small-city/{id}")
    public JsonResult getSmallCity(@PathVariable int id){
        return JsonResult.ok(hospitalService.getSmallCity(id));
    }

    @GetMapping("/levels")
    public JsonResult getLevels(){
        return JsonResult.ok(hospitalService.getAllLevel());
    }

    @GetMapping("/types")
    public JsonResult getTypes(){
        return JsonResult.ok(hospitalService.getAllType());
    }

    @PostMapping("/list")
    public JsonResult getHospitals(HospitalParam hospitalParam){
        return JsonResult.ok(hospitalService.getHospitals(hospitalParam));
    }


}
